//
//  DHLoginController.m
//  精品酒店
//
//  Created by DIANGHONG on 2018/5/8.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "DHLoginController.h"

@interface DHLoginController ()
@property(nonatomic ,strong)DHLoginView *loginView; //登录界面

@end

@implementation DHLoginController

- (DHLoginView *)loginView{
    __weak typeof(self) WeakSelf = self;
    if (!_loginView) {
        UINib *nib = [UINib nibWithNibName:@"DHLoginView" bundle:nil];
        _loginView = [nib instantiateWithOwner:nil options:nil][0];
        _loginView.frame = self.view.bounds;

        _loginView.noneLoginCloseViewBlock = ^(BOOL isSuccess) {
            if (!WeakSelf.isDismiss) {
                [WeakSelf.navigationController popViewControllerAnimated:true];
            }else{
                if (!isSuccess) {
                    DHMainController *mainVC = [[DHMainController alloc] init];
                    [UIApplication.sharedApplication.keyWindow setRootViewController:mainVC];
                    return ;
                }
                [WeakSelf dismissViewControllerAnimated:true completion:^{
                    
                    WeakSelf.webLogSuccful(WeakSelf.url);
                }];
            }
        };
        __weak typeof(_loginView) WeakloginView = _loginView;
        _loginView.registButtonClickBlock = ^{
            DHRegistViewController *rigestVC = [[DHRegistViewController alloc] init];

            [WeakSelf.navigationController pushViewController:rigestVC animated:true];

            rigestVC.RegistSuccessBlock = ^(NSString *userName)
            {
                WeakloginView.userName = userName;
            };
        };
        
        _loginView.forgetPwdBlock = ^{
         
            DHWebViewController *webVC = [[DHWebViewController alloc] init];
            webVC.urlStr = @"http://jpjd.com/wap/index.php?act=login&op=forget_password";
            webVC.hidesBottomBarWhenPushed = YES;
            if (WeakSelf.isDismiss) {
                [WeakSelf presentViewController:webVC animated:true completion:nil];
            }else{
                [WeakSelf.navigationController pushViewController:webVC animated:true];
            }
            
        };
    }
    return _loginView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view addSubview:self.loginView];

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}

@end
